import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import 'font-awesome/css/font-awesome.min.css'

import {postRequest} from "./utils/api";
import {postKeyValueRequest} from "./utils/api";
import {getRequest} from "./utils/api";
import {putRequest} from "./utils/api";
import {deleteRequest} from "./utils/api";

import {initMenu} from "./utils/menu";

Vue.prototype.postRequest = postRequest;
Vue.prototype.postKeyValueRequest = postKeyValueRequest;
Vue.prototype.getRequest = getRequest;
Vue.prototype.putRequest = putRequest;
Vue.prototype.deleteRequest = deleteRequest;

Vue.config.productionTip = false

//导航守卫
router.beforeEach((to, from, next) => {
  if(to.path == "/"){
    next();
  }else{
    if(window.sessionStorage.getItem("user")){//已登录正常访问
      initMenu(router,store);
      next();
    }else{//未登录重定向
      next('/?redirect='+to.path);
    }

  }
})

Vue.use(ElementUI, {size: 'small'});

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
